##

ALLIANCE_TOP	= /opt/alliance-5.0

ENV_ASIMUT	= MBK_CATAL_NAME=CATAL_ASIMUT

ENV_COUGAR	= MBK_SPI_MODEL=$(ALLIANCE_TOP)/etc/spimodel.cfg ;\
		  export MBK_SPI_MODEL;\
		  MBK_IN_PH=ap ;\
		  export MBK_IN_PH;\
		  MBK_OUT_LO=spi;\
		  export MBK_OUT_LO
	
all: translate check-behavioral synthesis place-route transistors

#------------------------------------------------------------------------------
# Translate to Alliance VHDL

translate: banderas.vbe

banderas.vbe: banderas.vhdl
	vasy -Vaop -I vhdl banderas
#------------------------------------------------------------------------------
# Simulate

check-behavioral:  banderas.vbe\
			test_ban.pat result_sim.pat

test_ban.pat: test_banderas.c
	genpat test_banderas

result_sim.pat: banderas.vbe test_ban.pat
	$(ENV_ASIMUT) asimut -b banderas test_ban result_sim

view-behav: result_sim.pat
	xpat -l result_sim 

#------------------------------------------------------------------------------
# ETAPA DE SYNTHESIS

synthesis: banderas_boom.vbe banderas_boog.vst banderas_loon.vst 

banderas_boom.vbe: banderas.vbe
	boom banderas banderas_boom

banderas_boog.vst: banderas_boom.vbe
	boog banderas_boom banderas_boog

banderas_loon.vst: banderas_boog.vst
	loon -o banderas_boog banderas_loon

view-gates: banderas.vbe
	xsch -l banderas

#------------------------------------------------------------------------------
# PLACE AND ROUTE

place-route: synthesis banderas_ocp.ap banderas_nero.ap banderas_real.cif 

banderas_ocp.ap: banderas_loon.vst

	ocp -rows 3 banderas_loon banderas_ocp

banderas_nero.ap: banderas_ocp.ap banderas_loon.vst
	nero -p banderas_ocp banderas_loon banderas_nero

banderas_real.cif: banderas_nero.ap
	s2r banderas_nero banderas_real

banderas_s2r.cif: banderas_nero.ap
	s2r banderas_nero banderas_s2r

view-place: synthesis banderas_ocp.ap
	graal -l banderas_ocp

view-route: synthesis banderas_nero.ap
	graal -l banderas_nero

view-real: synthesis banderas_s2r.cif
	dreal -l banderas_s2r

#------------------------------------------------------------------------------
# LISTA DE TRANSISTORES

transistors: place-route banderas_transistors.spi 

banderas_transistors.spi: banderas_nero.ap
	$(ENV_COUGAR); cougar -t banderas_nero banderas_transistors
	
spice-banderas_transistors: banderas_transistors.spi
	$(ENV_COUGAR); xsch -I spi -l banderas_transistors
	
clean:
	rm -rf  *.pat \
		*.vst \
		*.xsc \
		*.vbe \
		*.boom \
		*.ap \
		*.cif \
		*.spi \
		*.dat
